package com.gufe.controller.admin.preReserve;

import com.gufe.dto.adminPreReserve.PreReserveMembersExcelDTO;
import com.gufe.dto.adminPreReserve.PreReservePageMembersDTO;
import com.gufe.dto.prereserve.BasicInfoDTO;
import com.gufe.dto.prereserve.PreReserveInfoDTO;
import com.gufe.dto.prereserve.UpdateInfoDTO;
import com.gufe.mapper.admin.index.IndexMapper;
import com.gufe.result.PageResult;
import com.gufe.result.Result;
import com.gufe.service.admin.preReserve.PreReserveMemberService;
import com.gufe.vo.adminPreReserve.PreReserveMemberDetialVO;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@Slf4j
@RestController
@RequestMapping("/admin/preReserve")
@PreAuthorize("hasRole('ADMIN')")
public class PreReserveMemberController {

    @Autowired
    private PreReserveMemberService preReserveMemberService;
    @Autowired
    private IndexMapper indexMapper;

    /*获取单个学生的详细信息*/
    @GetMapping("/memberInfo/{studentId}")
    public Result<PreReserveMemberDetialVO> memberInfo(@PathVariable String studentId) {
        log.info("查询学生详细信息studentId:{}", studentId);
        PreReserveMemberDetialVO preReserveMemberDetialVO = preReserveMemberService.getMemberDetialInfo(studentId);
        return Result.success(preReserveMemberDetialVO);
    }

    /*导出单个学生详细信息Excel*/
    @GetMapping("/personalExcelInfo/{studentId}")
    public Result memberExcelInfo(@PathVariable String studentId, HttpServletResponse response) {
        log.info("导出学生Excel信息studentId:{}", studentId);
        preReserveMemberService.getMemberExcelInfo(studentId, response);
        return Result.success();
    }

    /*分页条件查询*/
    @GetMapping("/members")
    public Result<PageResult> getPageMembers(PreReservePageMembersDTO preReservePageMembersDTO) {
        log.info("分页查询预储成员！");
        PageResult pageResult = preReserveMemberService.getPageMembers(preReservePageMembersDTO);
        return Result.success(pageResult);
    }

    /*批量导出学生数据列表*/
    @PostMapping("/membersExcelList")
    public Result getMemberExcelList(@RequestBody PreReserveMembersExcelDTO preReserveMembersExcelDTO, HttpServletResponse response) {
        log.info("导出预储成员{}excel列表", Arrays.toString(preReserveMembersExcelDTO.getStudentIds()));
        preReserveMemberService.getMembersExcelList(preReserveMembersExcelDTO, response);
        return Result.success();
    }

    /*批量导出每个学生Excel详细信息*/
    @PostMapping("/membersExcel")
    public Result getMembersExcelInfoList(@RequestBody PreReserveMembersExcelDTO preReserveMembersExcelDTO, HttpServletResponse response) {
        log.info("导出学生{}详细信息excel", Arrays.toString(preReserveMembersExcelDTO.getStudentIds()));
        preReserveMemberService.getMembersExcelInfoList(preReserveMembersExcelDTO, response);
        return Result.success();
    }

    /*批量导出每个学生PDF详细信息*/
    @PostMapping("/membersPDF")
    public Result getMembersPDFInFoList(@RequestBody PreReserveMembersExcelDTO preReserveMembersExcelDTO, HttpServletResponse response) {
        log.info("导出学生{}详细信息PDF", Arrays.toString(preReserveMembersExcelDTO.getStudentIds()));
        preReserveMemberService.getMembersPDFInfoList(preReserveMembersExcelDTO, response);
        return Result.success();
    }

    /*获取预储总人数*/
    @GetMapping("/preReserveCount")
    public Result preReserveCount() {
        return Result.success(indexMapper.getTotalReserveCount());
    }


    //更新学生信息
    @PutMapping("/updatePersonInfo")
    public Result updatePreReserveInfo(@RequestBody UpdateInfoDTO updateInfoDTO) {
        log.info("更新预储成员基础信息{}", updateInfoDTO);
        preReserveMemberService.updateInfoDTO(updateInfoDTO);
        return Result.success();
    }
}
